package org.ex;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.Calendar;

public class Ex02 {
    public static void main(String[] args) {
        System.out.printf("今日是：%tF %<tA%n",System.currentTimeMillis());

        LocalDate now = LocalDate.now();
        System.out.printf("%tF%n",now);

        now = now.with(TemporalAdjusters.firstDayOfMonth());
        System.out.printf("%tF%n",now);


        //月初
        now = now.minus(now.getDayOfMonth()-1, ChronoUnit.DAYS);
        System.out.printf("%tF%n",now);

        now = LocalDate.of(now.getYear(),now.getMonthValue(),1);
        System.out.printf("%tF%n",now);

        //月末
        now = LocalDate.of(now.getYear(), now.getMonthValue() + 1, 1).minusDays(1);
        System.out.printf("%tF%n",now);

        Calendar c = Calendar.getInstance();
        c.set(Calendar.MONTH,c.get(Calendar.MONTH)+1);
        c.set(Calendar.DATE,0);
        System.out.printf("%tF%n",c);


        now = now.with(TemporalAdjusters.lastDayOfMonth());
        System.out.printf("%tF%n",now);
    }
}
